/**
 * Author shuqi
 * Rev
 * Date: 2021-07-31 10:58
 * <p>
 * Copyright (C) 2021 Seeyon, Inc. All rights reserved.
 * <p>
 * This software is the proprietary information of Seeyon, Inc.
 * Use is subject to license terms.
 * @company seeyon.com
 * @author shuqi
 * @since V5 V7.1
 */
package com.synnex.springboot.application;

import com.synnex.springboot.config.AppConfig;
import org.apache.catalina.startup.Tomcat;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

/**
 * @description
 * @date 2021-07-31 10:58
 * @author xiaol
 */
public class SpringApplication {

	public static void run(Class<?> clazz, String[] args) {
		initIoc(clazz);
		startTomcat();
	}

	/**
	 * 初始化ioc容器
	 */
	private static void initIoc(Class<?> clazz) {
		AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
		applicationContext.register(clazz);
		applicationContext.register(AppConfig.class);
		applicationContext.refresh();
	}

	/**
	 * 启动tomcat
	 */
	private static void startTomcat() {
		try {
			Tomcat tomcat = new Tomcat();
			tomcat.setPort(8080);
			tomcat.addWebapp("/", "D:\\project_spaces\\project_spaces\\git-cache\\springboot-synnex\\demo\\src\\main\\resources");
			tomcat.start();
			//线程挂起
			tomcat.getServer().await();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


}
